package com.kylin.common.weixin.miniapp;


import com.alibaba.fastjson2.JSONObject;
import com.kylin.common.weixin.util.WxRequest;

/**
 * token服务
 * 小程序和公众号均适用
 *
 * @author wuhao
 * @version 1.0 - 2019-11-20
 */
public class AccessTokenService {

    /**
     * 获取接口的鉴权token
     */
    private static final String ACCESS_TOKEN_URL = "/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";

    /**
     * 获取接口鉴权token
     * @param appid 公众号的唯一标识
     *
     * @param appSecret 公众号的appsecret
     * @return eg.{"access_token":"ACCESS_TOKEN","expires_in":7200}
     * @version 1.0  by wuhao at 2019-03-04
     */
    public static JSONObject getAccessToken(String appid, String appSecret){
        String url = String.format(ACCESS_TOKEN_URL,appid,appSecret);
        return WxRequest.get(url);
    }
}
